﻿<template>
  <div class="l-rblock l-form-viewer" style="padding:8px;">
    <el-form
      :model="formData"
      :rules="rules"
      size="mini"
      labelPosition="right"
      labelWidth="64px"
      ref="form"
    >
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane
            class="l-tabs-container"
            :label="$t('主表信息')"
            name="tab0"
          >
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col
                  v-if="lr_formLookAuth('lr_plugin_config_f_File')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('插件')"
                    prop="lr_plugin_config_f_File"
                  >
                    <l-upload
                      v-model="formData.lr_plugin_config_f_File"
                      accept=".zip"
                      maxSize="10"
                      sizeType="MB"
                      :limit="1"
                      :isTip="lr_formEditAuth(
                        'lr_plugin_config_f_File',
                        isReadOnly
                      )"
                      :disabled="
                        !lr_formEditAuth(
                          'lr_plugin_config_f_File',
                          false || isReadOnly
                        )
                      "
                      :placeholder="$t('please enter')"

                      @success="handleFileSuccess"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('lr_plugin_config_f_Name')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('名称')"
                    prop="lr_plugin_config_f_Name"
                  >
                    <el-input
                      disabled
                      v-model="formData.lr_plugin_config_f_Name"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('lr_plugin_config_f_Code')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('编码')"
                    prop="lr_plugin_config_f_Code"
                  >
                    <el-input
                      disabled
                      v-model="formData.lr_plugin_config_f_Code"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('lr_plugin_config_f_Version')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('版本')"
                    prop="lr_plugin_config_f_Version"
                  >
                    <el-input
                      disabled
                      v-model="formData.lr_plugin_config_f_Version"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('lr_plugin_config_f_Description')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('备注')"
                    prop="lr_plugin_config_f_Description"
                  >
                    <el-input
                      type="textarea"
                      :disabled="
                        !lr_formEditAuth(
                          'lr_plugin_config_f_Description',
                          isReadOnly
                        )
                      "
                      :rows="4"
                      v-model="formData.lr_plugin_config_f_Description"
                      :placeholder="$t('please enter')"
                    />
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>

<script>
const api = window.$api.plugin.pluginconfig;
export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      moduleCode: "plugin_config",
      activeName: "tab0",
      formData: {
        lr_plugin_config_f_Name: "", // 插件名称
        lr_plugin_config_f_Version: "", // 版本号
        lr_plugin_config_f_Description: "", // 备注
        lr_plugin_config_f_Code:"",
        lr_plugin_config_f_File: "", // 插件(ZIP)
      },
      rules: {
        lr_plugin_config_f_Name: [
          {
            required: true,
            message: "please enter",
          }
        ],
        lr_plugin_config_f_Version: [
          {
            required: true,
            message: "please enter",
          },
        ],
        lr_plugin_config_f_Code: [
          {
            required: true,
            message: "please enter",
          }
        ],
        lr_plugin_config_f_File: [
          {
            required: true,
            message: "请上传",
          },
        ],
      },
    };
  },
  computed: {},
  methods: {
    handleFileSuccess(){
      //console.log(api,'api');
      this.$nextTick(async()=>{
        var info = await this.$awaitWraper(api.getInfo(this.formData.lr_plugin_config_f_File));

        this.formData.lr_plugin_config_f_Name = info.name;
        this.formData.lr_plugin_config_f_Code = info.code;
        this.formData.lr_plugin_config_f_Version = info.version;
        this.formData.lr_plugin_config_f_Description = info.des;
        console.log(info,'info');
      });
      


      
    },
    // Reset表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.formData.lr_plugin_config_f_Id = "";
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }
      return true;
    },
    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "lr_plugin_config");
    },
    // 获取表单数据
    getForm() {
      return this.$getFormData(this.formData, "lr_plugin_config");
    },
    // 打印
    getPrintData() {
      // 此方法用来返回打印需要的数据
      return {};
    },
    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(api.get(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },
    async saveForm({ keyValue, isEdit /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();
      if (isEdit) {
        // Edit
        return await this.$awaitWraper(api.update(keyValue, postData));
      } else {
        // Add
        postData.f_Id = keyValue;
        return await this.$awaitWraper(api.add(postData));
      }
    },
  },
};
</script>
